<!DOCTYPE html>
<html>
  <head>

    <title><%=h yield(:title) %> » Peaksel</title>
    <%= stylesheet_link_tag    "application" %>
    <%= javascript_include_tag "application" %>
    <%= csrf_meta_tags %>

    <link rel="shortcut icon" href="/assets/favicon.ico" />

  </head>
  <body>

    <header class="main">

      <% if user_signed_in? %>
      <p><%= link_to "se déconnecter", destroy_user_session_path, {:title => "déconnexion"} %></p>
      <p>
        <%= image_tag current_user.avatar.url(:thumb) %>
        <%= link_to current_user, edit_user_registration_path, {:title => "profile"} %>
      </p>
      <% else %>
      <p><%= link_to "S'inscrire", new_user_path, {:title => "inscription"} %></p>
      <p><%= link_to "Se connecter", new_user_session_path, {:title => "connexion"} %></p>
      <% end %>

    <nav>
      <ul>
        <li><%= link_to 'Accueil', root_path, {:title => "accueil"} %></li>
        <li><%= link_to 'Annonces', ads_path, {:title => "voir toutes les annonces"} %></li>
        <li><%= link_to 'Membres', users_path, {:title => "voir tous les membres"} %></li>
        <li><%= link_to 'Transaction directe', new_transaction_path, {:title => "transaction directe"} %></li>
        <% if user_signed_in? and current_user.admin? %>
        <li><%= link_to 'Administration', rails_admin_path, {:title => "administration"} %></li>
        <% end %>
      </ul>
    </nav>

      <h1><%= link_to 'Peaksel', root_path, {:title => "accueil"} %></h1>

    </header>

    <div id="container">

    <%= render 'searchform' %>

    <p class="alert"><%= alert %></p>

    <%= yield %>

    <aside class="lateral_panel">
      <% if user_signed_in? %>
        <p>Peaksels : <%= current_user.money %> <%= image_tag("peak.png") %></p>

        <p><%= link_to "Nouvelle annonce", new_ad_path %></p>

        <header>
          <h1>Mes annonces</h1>
        </header>

        <% current_user.ads.each_with_index do |ad, i| break if i == 10 %>
          <div>
            <p>
              <%= link_to ad.label, ad, {:title => "voir " + ad.label } %>
              <%=
                link_to image_tag("edit.png"),
                {:controller => 'ads', :action => 'edit', :id => ad},
                {:title => "Editer " + ad.label}
              %>
              <%= link_to image_tag("delete.png"), ad, confirm: 'Are you sure?', method: :delete %>
            </p>
            <p><%=t truncate(ad.description, :length => 30, :separator => ' ') %></p>
            <p>Le <%=l ad.created_at %></p>
          </div>
        <% end %>
        <p><%= link_to 'Voir toutes mes annonces', list_ads_path, {:title => 'Toutes mes annonces'} %></p>

        <header>
          <h1>Mes derniers commentaires</h1>
        </header>

        <% current_user.comments.each_with_index do |comment, i| break if i == 10 %>
          <div>
            <p>
              <%= link_to comment.title, comment.offer.ad, {:title => "voir " + comment.title } %>
            </p>
            <p><%=t truncate(comment.content, :length => 30, :separator => ' ') %></p>
          </div>
        <% end %>

      <% else %>

        <header>
          <h1>Je n'ai pas de compte</h2>
          <p><%= link_to "Je m'inscris", new_user_path %></p>

          <h1>Je me connecte</h1>
          <p><%= link_to 'Je me connecte', new_user_session_path %></p>
        </header>

      <% end %>

    </aside>

    <footer class="main">
      <h1>Peaksel</h1>

      <nav>
        <ul>
          <% Page.all.each do |page| %>
          <li><%= link_to page.title, page %></li>
          <% end %>
        </ul>
      </nav>
      <p>Site développé dans le cadre de la licence Communication & Médias</p>
      <p>
        Licence
        <%=
          link_to 'CC-by-nc',
          'https://creativecommons.org/licenses/by-nc/3.0/',
          {:title => "Licence Attribution-NonCommercial"}
        %>
      </p>
    </footer>

  </div>

  </body>
</html>
